<include file="__THEME__/public_header" />
<div class="content">
	<div class="wrap">
    	<div class="con_side">
        	<ul class="nav">
            	<li><a href="{:U('admin/Privilege/index')}">市级账号</a></li>
                <li class="cursor"><a href="{:U('admin/Privilege/show_area_user')}">区级账号</a></li>
                <li><a href="{:U('admin/Privilege/show_garden_user')}">园级账号</a></li>
            </ul>
        </div>
        <div class="con_main">
        	<div class="con_tit">
            	<ul class="con_link">
                    <li><a href="{:U('admin/Privilege/show_area_user')}">筛选</a></li>
                    <li class="on"><a href="javascript:;">新建用户</a></li>
                </ul>
            </div>
            <div class="con_box">
                <ul class="slect_list2">
                    <li>
                        <div class="txt">选择省级：</div>
                        <div class="inp">
                            <select id="Province" onchange="selectArea(1);">
                                <option value="">----请选择----</option>
                                <volist name="province" id="province">
                                    <option value="{$province.area_id}">{$province.title}</option>
                                </volist>
                            </select>
                        </div>
                    </li>
                </ul>
                <ul class="slect_list2">
                     <li>
                        <div class="txt">选择市级：</div>
                        <div class="inp">
                            <select id="City" onchange="selectArea(2);">
                                <option value="0">----请选择----</option>
                            </select>
                        </div>
                    </li>
                </ul>
                <ul class="slect_list2">
                     <li>
                        <div class="txt">选择区级：</div>
                        <div class="inp">
                            <select id="Area" onchange="changeName()">
                                <option value="0">----请选择----</option>
                            </select>
                        </div>
                    </li>
                </ul>
                <ul class="slect_list2">
                     <li>
                        <div class="txt">用户名：</div>
                        <div class="inp">
                            <input type="text" id="uname" style="height:30px;">
                        </div>
                    </li>
                </ul>
                <ul class="slect_list2">
                     <li>
                        <div class="txt">密码：</div>
                        <div class="inp">
                            <input type="text" id="pwd" style="height:30px;">
                        </div>
                    </li>
                </ul>
                <div class="action_link tc small">
                    <a class="save" href="javascript:doAddUser();">确定</a>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function changeName(){
         if(Area=$("#Area").val()>0){
            $("#uname").val($("#Area   option:selected").text());
        }
    }
    function selectArea(type){
        if(type==1){
            var pid=$("#Province").val();
            var name="City";
        }else{
            var pid=$("#City").val();
            var name="Area";
        }
        if(pid>0){
            $.ajax({
              type: "GET",
              url:"{:U('public/TestData/getArea')}",
              data:"pid="+pid,
              dataType:"json",
              success:function(data){
                $("#"+name).html("");
                $("#"+name).append("<option value='0'>----请选择----</option>");
                $.each(data,function(i,item){
                  $("#"+name).append("<option value='"+item.area_id+"'>"+item.title+"</option>");
                }); 
              }
            });
        }
    }
    function doAddUser(){
        var Province=$("#Province").val();
        var City=$("#City").val();
        var Area=$("#Area").val();
        var uname=$("#uname").val();
        var location=$("#City   option:selected").text()+$("#Area   option:selected").text();
        var pwd=$("#pwd").val();
        if(Area==0){
            alert("请选择地区");
            return;
        }
        if(uname==""){
            alert("请输入用户名");
            return;
        }
        if(pwd==""){
            alert("请输入密码");
            return;
        }
        $.ajax({
            type: "POST",
            url:"{:U('admin/Privilege/addUser')}",
            data:"usertype=3&Province="+Province+"&City="+City+"&uname="+uname+"&Area="+Area+"&pwd="+pwd+"&location="+location,
            dataType:"text",
            success:function(data){
                if(isNaN(data)){
                    alert(data);
                }else{
                    window.location.href="{:U('admin/Privilege/show_area_user')}";
                }
            }
        });
    }
</script>
<include file="__THEME__/public_footer" />